package com.dayatang.exam.domain;

import javax.persistence.Column;
import javax.persistence.Embeddable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.dayatang.domain.ValueObject;

/**
 * 选择题�?项�?是从属于单�?题或多�?题的值对�?
 * @author yang
 *
 */
@Embeddable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class QuestionOption implements ValueObject, Comparable<QuestionOption>{

	private static final long serialVersionUID = -7590774969398537250L;

	@Column(nullable = false)
	private String text;

	public QuestionOption() {
	}

	public QuestionOption(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof QuestionOption))
			return false;
		QuestionOption castOther = (QuestionOption) other;
		return new EqualsBuilder().append(text, castOther.text).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(text).toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("text", text).toString();
	}

	public int compareTo(QuestionOption other) {
		if (other == null) {
			return 1;
		}
		return text.compareTo(other.getText());
	}
	
}
